package com.myview;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.VideoView;

import androidx.annotation.RequiresApi;

/**
 * Created by 0.0 on 2018/5/7.
 */

public class MyVideoView extends VideoView {

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = getDefaultSize(getWidth(), widthMeasureSpec);
        int height = getDefaultSize(getHeight(), heightMeasureSpec);
        setMeasuredDimension(width, height);
    }



    private PlayListener playListener;
    public interface PlayListener{
        public void onPause();
        public void onStart();

    }
    public MyVideoView(Context context) {
        super(context);
    }

    public MyVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setPlayListener(PlayListener playListener) {
        this.playListener = playListener;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public MyVideoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public void pause() {
        super.pause();
        if(playListener==null){

        }else {
            playListener.onPause();
        }
    }

    @Override
    public void start() {
        super.start();
        if(playListener==null){

        }else {
            playListener.onStart();
        }
    }



}
